package com.syt.utils;

import com.syt.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: xxx
 * @Date: 2023/2/25 16:26
 * @Description: 获取用户信息
 */
public class AuthContextHolder {

    //获取当前用户id
    public static Long getUserId(HttpServletRequest request){
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token中获取userid
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取当前用户的名称
    public static String getUserName(HttpServletRequest request){
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token中获取userid
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
